package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.bean.Bangindexbean;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 作者： 张贤伟
 * 时间： 2017/3/11 15:25
 * 类描述：番剧索引适配器
 */
public class Bangindexadapter extends RecyclerView.Adapter<Bangindexadapter.ViewHolder> {
    private Context context;

    public Bangindexadapter(Context context) {
        this.context = context;
    }

    private List<Bangindexbean.ResultEntity.CategoryEntity> list;

    public void initdata(List<Bangindexbean.ResultEntity.CategoryEntity> list) {
        this.list = list;
        this.notifyDataSetChanged();

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_bangumi_index, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.name.setText(list.get(position).getTag_name());
//        holder.describe.setText(list.get(position).getDesc());
        Glide.with(context).load(list.get(position).getCover()).into(holder.imageView);

    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView name, describe;

        public ViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.item_img);
            name = (TextView) itemView.findViewById(R.id.item_title);
//            describe = (TextView) itemView.findViewById(R.id.bangcard_describe);
        }
    }
}
